﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WeifenLuo.WinFormsUI.Docking;
using Willson.JsbManager.Comm;

namespace Willson.JsbManager.UI
{
    public partial class MainForm : Form
    {
        #region 窗口对象
        private MainToolForm mainToolForm = null;
        private DefaultForm defaultForm = null;
        #endregion

        #region 成员变量定义
        /// <summary>
        /// 用户ID号
        /// </summary>
        private int m_user_id = 0;
        /// <summary>
        /// 用户名称
        /// </summary>
        private string m_user_name = string.Empty;
        #endregion

        public int User_id
        {
            get { return m_user_id; }
        }

        public MainForm()
        {
            InitializeComponent();
            defaultForm = new DefaultForm(this);
            mainToolForm = new MainToolForm(this);

        }

        public void ResetQuickMenuList()
        {
            defaultForm.InitMenuList();
        }

        /// <summary>
        /// 登陆成功调用函数
        /// </summary>
        /// <param name="user_id">用户ID号</param>
        /// <param name="user_name">用户名称</param>
        public void Login(int user_id,string user_name)
        {
            this.m_user_id = user_id;
            this.m_user_name = user_name;

            this.statusStrip.Items["login_user_name"].Text = "当前用户:" + this.m_user_name;

            mainToolForm.InitMenu(this.m_user_id);

            WinInfo info = new WinInfo();
            info.User_id = user_id;

            //defaultForm.InitWinInfo(info);


            mainToolForm.Show(this.dockPanel, DockState.DockLeft);
            defaultForm.Show(this.dockPanel);

        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            
            LoginForm login = new LoginForm(this);
            login.ShowDialog();

        }

        /// <summary>
        /// 打开指定窗口
        /// </summary>
        /// <param name="name">窗口名称</param>
        public void OpenWindows(WinInfo info,OpenWindowType type)
        {
            try
            {
                BaseForm form = (BaseForm)Activator.CreateInstance(Type.GetType("Willson.JsbManager.UI." + info.Form_name));
                form.InitWinInfo(info);
                if (type == OpenWindowType.Show)
                    form.Show(this.dockPanel);
                else
                    form.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageUtil.ShowWarning(ex.Message);
            }
        }

    }
}
